﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Xml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames
{
    [Serializable]
    [DesignerCategory("code")]
    [XmlType(Namespace = "http://www.blizzard.com/wow/ui/")]
    [XmlRoot(Namespace = "http://www.blizzard.com/wow/ui/", IsNullable = false)]
    public class EditBox : Frame
    {
        /// <summary>
        /// Gets or sets the name of the font for the edit box.
        /// </summary>
        [XmlAttribute("font")]
        [Category("Appearance")]
        [Description("The font used to display the text.")]
        public string Font
        {
            get { return Properties.GetValue<string>("Font"); }
            set { Properties.SetValue("Font", value); }
        }

        /// <summary>
        /// Gets or sets the number of letters allowed in the edit box. The default value is unlimited (0).
        /// </summary>
        [XmlAttribute("letters")]
        [DefaultValue(0)]
        [Category("Behavior")]
        [Description("Defines the maximum characters to allow in a text box. The default value is unlimited (0).")]
        public int Letters
        {
            get { return Properties.GetValue<int>("Letters"); }
            set { Properties.SetValue("Letters", value); }
        }

        /// <summary>
        /// Gets or sets the blink speed of the edit box in seconds. The default value is 0.5.
        /// </summary>
        [XmlAttribute("blinkSpeed")]
        [DefaultValue(0.5f)]
        [Category("Appearance")]
        [Description("Define the blink speed of the edit box in seconds. The default value is 0.5.")]
        public float BlinkSpeed
        {
            get { return Properties.GetValue<float>("BlinkSpeed"); }
            set { Properties.SetValue("BlinkSpeed", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the edit box is numeric. The default is false.
        /// </summary>
        [XmlAttribute("numeric")]
        [DefaultValue(false)]
        [Category("Behavior")]
        [Description("Tells the text box to accept only numeric values. The default is false.")]
        public bool Numeric
        {
            get { return Properties.GetValue<bool>("Numeric"); }
            set { Properties.SetValue("Numeric", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the edit box should be in password mode. The default is false.
        /// </summary>
        [XmlAttribute("password")]
        [DefaultValue(false)]
        [Category("Behavior")]
        [Description("Defines a value indicating whether the edit box should be in password mode. The default is false.")]
        public bool Password
        {
            get { return Properties.GetValue<bool>("Password"); }
            set { Properties.SetValue("Password", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the edit box is multiline. The default is false.
        /// </summary>
        [XmlAttribute("multiLine")]
        [DefaultValue(false)]
        [Category("Behavior")]
        [Description("Tells a text box to span multiple lines (<Enter> inserts a line break).")]
        public bool MultiLine
        {
            get { return Properties.GetValue<bool>("MultiLine"); }
            set { Properties.SetValue("MultiLine", value); }
        }

        /// <summary>
        /// Gets or sets the number of history lines for the edit box. The default is unlimited (0).
        /// </summary>
        [XmlAttribute("historyLines")]
        [DefaultValue(0)]
        [Category("Appearance")]
        [Description("Defines the number of history lines for the edit box. The default is unlimited (0).")]
        public int HistoryLines
        {
            get { return Properties.GetValue<int>("HistoryLines"); }
            set { Properties.SetValue("HistoryLines", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the edit box should auto-focus.
        /// </summary>
        [XmlAttribute("autoFocus")]
        [DefaultValue(true)]
        [Category("Behavior")]
        [Description("Automatically place the cursor bar inside a text box and receive all of the keyboard's attention.")]
        public bool AutoFocus
        {
            get { return Properties.GetValue<bool>("AutoFocus"); }
            set { Properties.SetValue("AutoFocus", value); }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the edit box should ignore the arrow keys.
        /// </summary>
        [XmlAttribute("ignoreArrows")]
        [DefaultValue(false)]
        [Category("Behavior")]
        [Description("Text fields will ignore directional arrows and move the character instead. (Holding <Alt> temporarily sets this to true). Default false.")]
        public bool IgnoreArrows
        {
            get { return Properties.GetValue<bool>("IgnoreArrows"); }
            set { Properties.SetValue("IgnoreArrows", value); }
        }

        /// <summary>
        /// Gets or sets the font string used with the edit box.
        /// </summary>
        [XmlElement]
        [Category("Appearance")]
        public FontString FontString
        {
            get { return Properties.GetValue<FontString>("FontString"); }
            set { Properties.SetValue("FontString", value); }
        }

        /// <summary>
        /// Gets a value indicating whether a serialization object is complete and can be rendered.
        /// </summary>
        public override bool IsComplete
        {
            get
            {
                return this.Layers.SelectMany(layer => layer.Items)
                           .OfType<Texture>()
                           .Count() > 0;
            }
        }
    }
}